<?php
/**
 * Created by PhpStorm.
 * User: HVAI
 * Date: 2018/4/1
 * Time: 22:29
 */

namespace app\api\logic;
use app\api\model\Company;
use think\Db;


class companyLogic
{
    public function get(){
       $res = Company::field('company_id,company_name,company_type')->where(['company_id'=>'4a9d599812e059bd7f9f2bffb4cfc97c'])->find();
       return $res;
    }
    
    public function getList($page=0){

        if($page){
            $page_count = 15;
            $show_page = ($page - 1) * $page_count;

            $res =  Company::field('company_id,company_name,company_type')->limit($show_page, $page_count)->select();
            $count = Company::field('company_id,company_name,company_type')->count();

            $arr['data_list'] = $res;
            $arr['page_data']['count'] = $count;
            $arr['page_data']['rows_num'] = $page_count;
            $arr['page_data']['page'] = $page;
        }else{
            $res =  Company::field('company_id,company_name,company_type')->select();

            $arr['data_list'] = $res;

        }
        return $arr;
    }

    public function save($data){

        $id = $data['id'];
        if($id){
           $res = Company::update($data,['id'=>$id]);
        }else{
            $res = Company::create($data);
        }

        return $res;
    }

    public function delete($id){

       $res=  Company::where(['company_id'=>$id])->delete();

       return $res;

    }

    public function text(){
        $res = Db::table('users')->find();
        return $res;
    }
}